<template>
  <div class="fill-q">
    <div class="content">
      <n-thing content-indented>
        <template #header v-if="formData.title">
          <n-row class="title">
            <div class="index" v-if="props.index">{{ props.index + '.' }}</div>
            <span v-show="formData.required === '必填'" style="color: red">
              *
            </span>
            {{ formData.title }}
            <span
              v-if="formData.score > 0"
              style="font-size: 0.8rem; color: #d83701; margin-left: 1px"
            >
              {{ '(' + formData.score + '分)' }}
            </span>
          </n-row>
        </template>
        <template #description v-if="formData.remark">
          <div class="remark">
            {{ '——' + formData.remark }}
          </div>
        </template>
        <n-input
          v-model:value="formData.fill"
          @update:value="upF"
          type="text"
          placeholder="请输入你的答案"
        />
      </n-thing>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Pencil as FlashIcon } from '@vicons/ionicons5';
import { ref, reactive, computed } from 'vue';

// 父组件传来的数据
const props = defineProps({
  index: {
    type: Number,
    default: 0,
  },
  title: {
    type: String,
    required: true,
  },
  required: {
    type: String,
    default: '非必填',
  },
  remark: {
    type: String,
    default: '',
  },
  checked: {
    type: String,
    default: '',
  },
  score: {
    type: Number,
    default: 0,
  },
  fill: {
    type: String,
    required: true,
  },
});

// 暂存数据
const formData: any = reactive({
  title: props.title,
  remark: props.remark,
  required: props.required,
  checked: props.required,
  score: props.score,
  fill: props.fill,
});

// 双向数据绑定，子组件emit
const emit = defineEmits(['update:fill']);
const upF = (value: string) => {
  emit('update:fill', value);
};

const formRef = ref(null);
</script>

<style scoped lang="scss">
.fill-q {
  .index {
    margin-right: 1vw;
  }
  .content {
    padding: 1vw;
  }
  .title {
    font-size: 1.25rem;
  }
  .remark {
    font-size: 1rem;
    color: #999;
  }
  .edit {
    padding: 0 5vw;
  }
}
</style>
